package com.yuanduo_app;

import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.View;

import com.yuanduo_app.consts.FileConst;
import com.yuanduo_app.manager.RecorderManager;
import com.yuanduo_app.manager.VideoPlayer;
import com.yuanduo_app.widget.CameraXCustomPreviewView;

import java.io.File;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.VideoCapture;

public class TestActivity extends AppCompatActivity {
    private CameraXCustomPreviewView mSurfaceView;
    private SurfaceHolder mSurfaceHolder;
    private RecorderManager mRecorderManager;
    private VideoPlayer mVideoPlayer;

    @Override
    protected void onCreate (@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        mSurfaceView = findViewById(R.id.viewFinder);
        mVideoPlayer = new VideoPlayer(findViewById(R.id.video_view));
        mRecorderManager = new RecorderManager();
        mRecorderManager.bindView(mSurfaceView);
        mRecorderManager.startCamera(this);
        findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v) {
                mRecorderManager.takeVideo(new VideoCapture.OnVideoSavedCallback() {
                    @Override
                    public void onVideoSaved (@NonNull File file) {

                    }

                    @Override
                    public void onError (int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {

                    }
                });
            }
        });
        findViewById(R.id.btn_stop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v) {
                mRecorderManager.stopTakeVideo();
            }
        });
        findViewById(R.id.btn_play).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v) {
                mVideoPlayer.play(FileConst.RECORD + FileConst.RECORD_CACHE);
            }
        });
    }

}
